import requests
from lxml import etree
from 爬取姓名 import Name
class get_teacher_url:
    def __init__(self,address):
        self.address=address  #一页的地址

    def get_url(self,path): #path为xpath表达式  得到一页的导师链接
        headers = {
            'accept-language': 'zh-CN,zh;q=0.9',
            'cache-control': 'max-age=0',
            'cookie': 'Hm_lvt_c3acb27768b401b6598a1ae2797371a4=1693548649,1693581545; '
                      'Hm_lpvt_c3acb27768b401b6598a1ae2797371a4=1693581548',
            'sec-fetch-dest': 'document',
            'sec-fetch-mode': 'navigate',
            'sec-fetch-site': 'same-origin',
            'sec-fetch-user': '?1',
            'upgrade-insecure-requests': '1',
            'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/'
                          '537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/'
                          '537.36 SLBrowser/7.0.0.6251 SLBChan/124'}

        # 获取响应
        response = requests.get(url=self.address, headers=headers)
        content = response.text
        #xpath表达式
        tree=etree.HTML(content)
        r=tree.xpath(path)
        url_list=[]
        for url in r:
            url="https://sdmda.bupt.edu.cn"+url[2:]
            url_list.append(url)
        return url_list

    def each_real_url(self,page_name,page_url): #address是得名字类那里得address，不是这个类得
        dict={}
        for name in page_name:
            dict[name] = ''  # 创建keys
        i = 0
        while i < len(page_name):
            name = page_name[i]
            dict[name] = page_url[i]
            i += 1
        # 得到了当前页得对应字典
        return dict





















